import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    // 用户信息
    user: null
  },
  mutations: {
    // 设置用户信息
    SetUser (state, user) {
      state.user = user
    },
    // 设置账号
    SetUserAccount (state, val) {
      if (state.user) {
        state.user.account = val
      }
    },
    // 设置手机号
    SetUserPhone (state, val) {
      if (state.user) {
        state.user.phoneNum = val
      }
    },
    // 设置昵称
    SetUserNick (state, val) {
      if (state.user) {
        state.user.nick = val
      }
    },
    // 设置头像
    SetUserAvatar (state, val) {
      if (state.user) {
        state.user.avatar = val
      }
    },
    // 设置签名
    SetUserSign (state, val) {
      if (state.user) {
        state.user.signature = val
      }
    },
    // 设置性别
    SetUserGender (state, val) {
      if (state.user) {
        state.user.gender = val
      }
    },
    // 设置生日
    SetUserBirth (state, val) {
      if (state.user) {
        state.user.birth = val
      }
    },
    // 设置密码
    SetUserPwd (state, val) {
      if (state.user) {
        state.user.password = val
      }
    }
  },
  actions: {
  },
  modules: {
  },
  getters: {
    // 获取用户信息
    GetUser: state => {
      return state.user
    },
    // 获取用户token
    GetUserToken: state => {
      if (state.user) {
        return state.user.token
      }
      return null
    }
  }
})
